package com.aaa.demo112.demo;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @Description:
 * @author:LiWei
 * @date:2022年11月02日9:15
 */
public class TestExecutor {
    public static void main(String[] args) {
        //创建单一线程池
        ExecutorService executorService=Executors.newSingleThreadExecutor();

        //创建固定长度的线程池
        ExecutorService executorService1=Executors.newFixedThreadPool(10);

        //创建可变长度的线程池
        ExecutorService executorService2=Executors.newCachedThreadPool();

        //延迟线程池
        ScheduledExecutorService scheduledExecutorService =Executors.newScheduledThreadPool(10);

        for (int i = 0; i < 10; i++) {
            final  int a=i;
            scheduledExecutorService.schedule(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName()+"===="+a);
                }
            },20,TimeUnit.SECONDS);

//            executorService.submit(new Runnable() {
//                @Override
//                public void run() {
//                    System.out.println(Thread.currentThread().getName()+"======="+a);
//                }
//            });
        }
        }
    }

